<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      html,
      body {
        height: 100%;
      }
      * {
        margin: 0;
        padding: 0;
      }
      canvas {
        border: 1px solid black;
        margin: 0 auto;
        display: block;
      }
    </style>
  </head>
  <body>
    <canvas width="500" height="500">浏览器版本过低</canvas>
    <script>
      // 获取画布
      const canvas = document.querySelector('canvas');
      // 获取画笔
      const c = canvas.getContext('2d');
      // 茶杯主体
      c.beginPath();
      c.rect(150, 200, 150, 150);
      c.lineWidth = 5;
      c.stroke();
      // 茶杯提手
      drawCircle(300, 280, 50, false, 5);

      // 茶杯热气
      for (let i = 0; i < 3; i++) {
        drawCircle(170 + 40 * i, 120, 20, true, 1);
        drawCircle(170 + 40 * i, 160, 20, false, 1);
      }

      // Fun 画半圆
      function drawCircle(x, y, r, counterclockwise, lineWidth = 1) {
        c.beginPath();
        c.arc(x, y, r, -Math.PI / 2, Math.PI / 2, counterclockwise);
        c.lineWidth = lineWidth;
        c.stroke();
      }
    </script>
  </body>
</html>
